package com.xhl.doeverything.rabbitmq.service;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.rabbitmq.client.Channel;
import com.xhl.doeverything.entity.SysEvent;
import com.xhl.doeverything.exception.BizException;
import com.xhl.doeverything.exception.ExceptionCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * mq消费者
 */
public class BaseEventReceiver {
    private static final Logger log = LoggerFactory.getLogger(BaseEventReceiver.class);

    public BaseEventReceiver() {
    }

    public void ack(Channel channel, long deliveryTag) {
        try {
            channel.basicAck(deliveryTag, true);
        } catch (IOException var5) {
            log.error("手工确认消息失败", var5);
            throw new BizException(ExceptionCode.HTTP_STATUS_INTERNAL_SERVER_ERROR.getCode(), "手工确认消息送达失败", new Object[0]);
        }
    }

    public <T> SysEvent<T> parseEvent(String eventStr, TypeReference<SysEvent<T>> type) {
        return (SysEvent)JSON.parseObject(eventStr, type, new Feature[0]);
    }

    public SysEvent<?> parseEventIgnoreException(String eventStr) {
        try {
            return (SysEvent)JSON.parseObject(eventStr, new TypeReference<SysEvent<?>>() {
            }, new Feature[0]);
        } catch (Exception var3) {
            log.error("解析消息异常，忽略处理:{}", eventStr, var3);
            return null;
        }
    }
}
